
#!/bin/bash
. /home/hongxi/baseUtil.sh

TODAY=`date +"%Y%m%d"`
lastTEN=$(date "-d -10 minute" +"%Y-%m-%d_%H_%M")
user=ra_house
passwd=3JWOFlrah3VxraBeu
database=qyer_lastminute
host=mysql_dm
port=3307
wareinginfo=$log_dir"mysqldailybak.waraing"
data_dir=/data3/logs/mysql/data/


echo "     " > $wareinginfo
echo "---------------------------------" >> $wareinginfo
echo $(date +"%y-%m-%d %H:%M:%S") >> $wareinginfo
echo "---------------------------------" >> $wareinginfo


#save data in file 

mkdir -p $data_dir$TODAY

mysql -u$user -p$passwd -h$host -P$port  -e "
use qyer_lastminute ; 
select l.id,c.pid,c.id,c.price,c.house_diff,l.recommend,l.views,l.modifytime,c.total,l.sort_sold_num,l.sort_time,l.sort_weight,l.sort_list_price 
from lastminute_main l 
left join lastminute_category c on l.id = c.lid 
where l.status=0 and l.onsale = 1 
and unix_timestamp(now()) between l.start_time and l.end_time and c.total>0 and c.type = 0 
and TIMESTAMPDIFF(MINUTE,from_unixtime(l.modifytime),now()) <= 11" >> $data_dir$TODAY"/"$lastTEN".data"

if [ $? = 0 ] ;then
 	#cd $binlog_dir
 	echo "save data in file  succeed" >> $wareinginfo
else 
 	echo "save data in file  fail" >> $wareinginfo
 	#mail -s "MySQL Backup" $eMail < $wareinginfo  #备份失败之后发送邮件通知
fi

